;;----------------------------------------------------------------------
;; plot zonal distribution of ion production 
;;----------------------------------------------------------------------
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
;load "$KAILIBROOT/lib_radon.ncl"

begin

  plotpath     = "~/fig/"
  plotname     = plotpath+"fig_latslice" 
  plotform     = "eps"
  ploteps      = plotname+".eps"
  plotpdf      = plotname+".pdf"
  plottype     = "lat_slice" 

  datapath = "./input/" 

  beglat   =  20.
  endlat   =  50. 
 ;beglon   =   0. 
 ;endlon   = 135. 
  beglon   = 0. 
  endlon   = 360. 

  llonFlip = True

  lavgLinesOn     = False 
  lpercentilesOn  = False 

  StringFontHeightF  = 0.030
  cnLineLabelFontHeightF = 0.025 
  tmXBLabelFontHeightF = 0.028
  tmYLLabelFontHeightF = 0.024
  tiMainFontHeightF  = 0.05 
  tiXAxisFontHeightF = 0.025
  tiYAxisFontHeightF = 0.028 ;;35
  lbLabelFontHeightF = 0.028 

  gsnStringFont = "helvetica-bold"
  gsnStringFont = "helvetica"
  
  np = 9 

  str = (/"","","","","","","","",""/) 

  tiYAxisString = str
  tiYAxisString = "Height above surface (m)"
 ;tiYAxisString(0) = "Height above surface (m)" 
 ;tiYAxisString(3) = "Height above surface (m)" 
 ;tiYAxisString(6) = "Height above surface (m)" 

  abcd = (/"a","b","c","d","e","f","g","h","i","j","k","l","m","n"/) 
  abcd = (/"a","b","a","d","e","b","g","h","c","j","k","l","m","n"/) 

  abcd = abcd + ") " 

  gsnLeftString = str

  stra = "WCRP1995 " 
  strb = "SW1998 / 1.6 " 
  strc = "Merged " 
 
  gsnLeftString(0) = abcd(0) + stra
  gsnLeftString(1) = abcd(1) + strb
  gsnLeftString(2) = abcd(2) + strc

  gsnLeftString(3) = abcd(3) + stra 
  gsnLeftString(4) = abcd(4) + strb
  gsnLeftString(5) = abcd(5) + strc

  gsnLeftString(6) = abcd(6) + stra 
  gsnLeftString(7) = abcd(7) + strb
  gsnLeftString(8) = abcd(8) + strc 
 
 ;gsnCenterString = str

  strx = "IPRR, 20~S~o~N~N-50~S~o~N~N average (cm~S~-3~N~ s~S~-1~N~)"
  stra = strx ;;+ "WCRP1995 " 
  strb = strx ;;+ "SW1998 / 1.6 " 
  strc = strx ;;+ "MERGE " 

 ;gsnCenterString(0) = stra
 ;gsnCenterString(1) = strb
 ;gsnCenterString(2) = strc 

 ;gsnCenterString(3) = stra 
 ;gsnCenterString(4) = strb
 ;gsnCenterString(5) = strc 

 ;gsnCenterString(6) = stra 
 ;gsnCenterString(7) = strb
 ;gsnCenterString(8) = strc 

;;----------------------------------------------------------------------
;; load files 
;;----------------------------------------------------------------------

  run1 = "RA008" 
  run2 = "RA010" 
  run3 = "RA007" 

  filenama = datapath+"out_"+run1+"_ANN.nc" 
  filenamb = datapath+"out_"+run1+"_DJF.nc" 
  filenamc = datapath+"out_"+run1+"_JJA.nc" 

  filenamf = datapath+"out_"+run2+"_ANN.nc" 
  filenamg = datapath+"out_"+run2+"_DJF.nc" 
  filenamh = datapath+"out_"+run2+"_JJA.nc" 

  filenami = datapath+"out_"+run3+"_ANN.nc" 
  filenamj = datapath+"out_"+run3+"_DJF.nc" 
  filenamk = datapath+"out_"+run3+"_JJA.nc" 

  fila = addfile(filenama,"r")
  filb = addfile(filenamb,"r")
  filc = addfile(filenamc,"r")

  filf = addfile(filenamf,"r")
  filg = addfile(filenamg,"r")
  filh = addfile(filenamh,"r")

  fili = addfile(filenami,"r")
  filj = addfile(filenamj,"r")
  filk = addfile(filenamk,"r")



;;----------------------------------------------------------------------
;; read data 
;;----------------------------------------------------------------------

  rna = fila->RN222    ;; radon  
  rma = fila->RN22290  ;; 90th percentile  
  pra = fila->IPRR     ;; ion production  
 
  rnb = filb->RN222
  rmb = filb->RN22290
  prb = filb->IPRR

  rnc = filc->RN222
  rmc = filc->RN22290
  prc = filc->IPRR

  rnf = filf->RN222
  rmf = filf->RN22290
  prf = filf->IPRR

  rng = filg->RN222
  rmg = filg->RN22290
  prg = filg->IPRR

  rnh = filh->RN222
  rmh = filh->RN22290
  prh = filh->IPRR

  rni = fili->RN222
  rmi = fili->RN22290
  pri = fili->IPRR

  rnj = filj->RN222
  rmj = filj->RN22290
  prj = filj->IPRR

  rnk = filk->RN222
  rmk = filk->RN22290
  prk = filk->IPRR

;;----------------------------------------------------------------------
;; new data structure for zonal average 
;;----------------------------------------------------------------------


  if(plottype.eq."zonal_average") then 

  prna = rna(0,:,:,0) 
  prnb = rnb(0,:,:,0) 
  prnc = rnc(0,:,:,0)

  prnf = rnf(0,:,:,0)
  prng = rng(0,:,:,0)
  prnh = rnh(0,:,:,0)

  prni = rni(0,:,:,0)
  prnj = rnj(0,:,:,0)
  prnk = rnk(0,:,:,0)

  prna = (/ dim_avg(rna(0,:,:,:)) /) ;; color fill  
  prnb = (/ dim_avg(rnb(0,:,:,:)) /) 
  prnc = (/ dim_avg(rnc(0,:,:,:)) /) 

  prnf = (/ dim_avg(rnf(0,:,:,:)) /) 
  prng = (/ dim_avg(rng(0,:,:,:)) /) 
  prnh = (/ dim_avg(rnh(0,:,:,:)) /) 

  prni = (/ dim_avg(rni(0,:,:,:)) /) 
  prnj = (/ dim_avg(rnj(0,:,:,:)) /) 
  prnk = (/ dim_avg(rnk(0,:,:,:)) /)  

  end if 


  if(plottype.eq."lat_slice") then 

  prna = rna(0,:,0,{beglon:endlon})
  prnb = rnb(0,:,0,{beglon:endlon})
  prnc = rnc(0,:,0,{beglon:endlon})

  prnf = rnf(0,:,0,{beglon:endlon})
  prng = rng(0,:,0,{beglon:endlon})
  prnh = rnh(0,:,0,{beglon:endlon})

  prni = rni(0,:,0,{beglon:endlon})
  prnj = rnj(0,:,0,{beglon:endlon})
  prnk = rnk(0,:,0,{beglon:endlon})
 
  rrna =  rna(time|:,lev|:,lon|:,lat|:) 
  rrnb =  rnb(time|:,lev|:,lon|:,lat|:) 
  rrnc =  rnc(time|:,lev|:,lon|:,lat|:) 

  rrnf =  rnf(time|:,lev|:,lon|:,lat|:) 
  rrng =  rng(time|:,lev|:,lon|:,lat|:) 
  rrnh =  rnh(time|:,lev|:,lon|:,lat|:) 

  rrni =  rni(time|:,lev|:,lon|:,lat|:) 
  rrnj =  rnj(time|:,lev|:,lon|:,lat|:) 
  rrnk =  rnk(time|:,lev|:,lon|:,lat|:) 

  prna = (/ dim_avg( rrna(0,:,{beglon:endlon},{beglat:endlat}) ) /) ;; color fill  
  prnb = (/ dim_avg( rrnb(0,:,{beglon:endlon},{beglat:endlat}) ) /) 
  prnc = (/ dim_avg( rrnc(0,:,{beglon:endlon},{beglat:endlat}) ) /) 

  prnf = (/ dim_avg( rrnf(0,:,{beglon:endlon},{beglat:endlat}) ) /) ;; color fill  
  prng = (/ dim_avg( rrng(0,:,{beglon:endlon},{beglat:endlat}) ) /) 
  prnh = (/ dim_avg( rrnh(0,:,{beglon:endlon},{beglat:endlat}) ) /) 

  prni = (/ dim_avg( rrni(0,:,{beglon:endlon},{beglat:endlat}) ) /) ;; color fill  
  prnj = (/ dim_avg( rrnj(0,:,{beglon:endlon},{beglat:endlat}) ) /) 
  prnk = (/ dim_avg( rrnk(0,:,{beglon:endlon},{beglat:endlat}) ) /)  

  end if 


  if(plottype.eq."zonal_average") then 

  prma = rma(0,:,:,0)
  prmb = rmb(0,:,:,0)
  prmc = rmc(0,:,:,0)

  prmf = rmf(0,:,:,0)
  prmg = rmg(0,:,:,0)
  prmh = rmh(0,:,:,0)

  prmi = rmi(0,:,:,0)
  prmj = rmj(0,:,:,0)
  prmk = rmk(0,:,:,0)

  prma = (/ dim_avg(rma(0,:,:,:)) /) ;; contour  
  prmb = (/ dim_avg(rmb(0,:,:,:)) /)
  prmc = (/ dim_avg(rmc(0,:,:,:)) /)

  prmf = (/ dim_avg(rmf(0,:,:,:)) /) 
  prmg = (/ dim_avg(rmg(0,:,:,:)) /) 
  prmh = (/ dim_avg(rmh(0,:,:,:)) /) 

  prmi = (/ dim_avg(rmi(0,:,:,:)) /) 
  prmj = (/ dim_avg(rmj(0,:,:,:)) /) 
  prmk = (/ dim_avg(rmk(0,:,:,:)) /)  

  end if 


  if(plottype.eq."lat_slice") then 

  prma = rma(0,:,0,{beglon:endlon})
  prmb = rmb(0,:,0,{beglon:endlon})
  prmc = rmc(0,:,0,{beglon:endlon})

  prmf = rmf(0,:,0,{beglon:endlon})
  prmg = rmg(0,:,0,{beglon:endlon})
  prmh = rmh(0,:,0,{beglon:endlon})

  prmi = rmi(0,:,0,{beglon:endlon})
  prmj = rmj(0,:,0,{beglon:endlon})
  prmk = rmk(0,:,0,{beglon:endlon})

  rrma =  rma(time|:,lev|:,lon|:,lat|:) 
  rrmb =  rmb(time|:,lev|:,lon|:,lat|:) 
  rrmc =  rmc(time|:,lev|:,lon|:,lat|:) 

  rrmf =  rmf(time|:,lev|:,lon|:,lat|:) 
  rrmg =  rmg(time|:,lev|:,lon|:,lat|:) 
  rrmh =  rmh(time|:,lev|:,lon|:,lat|:) 

  rrmi =  rmi(time|:,lev|:,lon|:,lat|:) 
  rrmj =  rmj(time|:,lev|:,lon|:,lat|:) 
  rrmk =  rmk(time|:,lev|:,lon|:,lat|:) 

  prma = (/ dim_avg( rrma(0,:,{beglon:endlon},{beglat:endlat}) ) /) ;; color fill  
  prmb = (/ dim_avg( rrmb(0,:,{beglon:endlon},{beglat:endlat}) ) /) 
  prmc = (/ dim_avg( rrmc(0,:,{beglon:endlon},{beglat:endlat}) ) /) 

  prmf = (/ dim_avg( rrmf(0,:,{beglon:endlon},{beglat:endlat}) ) /) ;; color fill  
  prmg = (/ dim_avg( rrmg(0,:,{beglon:endlon},{beglat:endlat}) ) /) 
  prmh = (/ dim_avg( rrmh(0,:,{beglon:endlon},{beglat:endlat}) ) /) 

  prmi = (/ dim_avg( rrmi(0,:,{beglon:endlon},{beglat:endlat}) ) /) ;; color fill  
  prmj = (/ dim_avg( rrmj(0,:,{beglon:endlon},{beglat:endlat}) ) /) 
  prmk = (/ dim_avg( rrmk(0,:,{beglon:endlon},{beglat:endlat}) ) /)  

  end if 

  if (llonFlip) then
  
  prna = lonFlip(prna)
  prnb = lonFlip(prnb)
  prnc = lonFlip(prnc)

  prnf = lonFlip(prnf)
  prng = lonFlip(prng)
  prnh = lonFlip(prnh)

  prni = lonFlip(prni)
  prnj = lonFlip(prnj)
  prnk = lonFlip(prnk)

  prma = lonFlip(prma)
  prmb = lonFlip(prmb)
  prmc = lonFlip(prmc)

  prmf = lonFlip(prmf)
  prmg = lonFlip(prmg)
  prmh = lonFlip(prmh)

  prmi = lonFlip(prmi)
  prmj = lonFlip(prmj)
  prmk = lonFlip(prmk)

  end if


;;----------------------------------------------------------------------
;; open wks  
;;----------------------------------------------------------------------

  wks = gsn_open_wks(plotform,plotname)               ; open a ps file

;;----------------------------------------------------------------------
;; colormap
;;----------------------------------------------------------------------

  colormap = "amwg"
  colormap = "ViBlGrWhYeOrRe"
  colormap = "testcmap"
  colorstart = 50
  colorend   = 190

  colormap = "ViBlGrWhYeOrRe"
  colorstart = 24
  colorend   = 95 

  colormap = "WhViBlGrYeOrReWh"
  colorstart = 5
  colorend   = 80                                                              

  colormap = "WhViBlGrYeOrRe"
  colorstart = 2
  colorend   = 102

  gsn_define_colormap(wks,colormap)         ; choose a colormap

;;----------------------------------------------------------------------
;; plot settings:  
;;----------------------------------------------------------------------
 
  res                  = True    ; contour mods desired
  res@gsnFrame         = False   ; don't draw yet
  res@gsnDraw          = False   ; don't advance frame yet
  res@gsnMaximize      = False   ; True

  res@tiMainOn         = False   ; no title 
  res@cnFillOn         = True    ; turn on color
  res@cnLinesOn        = False   ; turn off contour lines
  res@cnLineThicknessF = 1.     ; thicker lines
  res@cnLevelSelectionMode  = "ManualLevels"  ; set manual cn levels
 ;res@cnMinLevelValF   =    0.     ; set min contour level
 ;res@cnMaxLevelValF   = 8000.     ; set max contour level
 ;res@cnLevelSpacingF  = 1000.
  res@cnInfoLabelOn    = False    ; no contour labels
 ;res@cnFillMode       = "RasterFill"  ; turn on raster mode
 ;res@cnFillDrawOrder  = "PreDraw"     ; draw contours before continents

;;----------------------------------------------------------------------
;; colors  
;;----------------------------------------------------------------------

  res@gsnSpreadColors = True    ; use full colormap
  res@gsnSpreadColorStart = colorstart 
  res@gsnSpreadColorEnd   = colorend 

;;----------------------------------------------------------------------
;; strings 
;;----------------------------------------------------------------------
  res@gsnLeftString    = "" 
  res@gsnCenterString  = "" 
  res@gsnRightString   = ""

  res@gsnLeftStringFontHeightF   = StringFontHeightF 
  res@gsnCenterStringFontHeightF = StringFontHeightF 
  res@gsnRightStringFontHeightF  = StringFontHeightF 

  res@gsnStringFont = gsnStringFont 
  
;;----------------------------------------------------------------------
;; lable bar 
;;----------------------------------------------------------------------
  res@lbLabelBarOn       = True       ; no individual label bar
  res@lbLabelStride      = 1          ; every other label bar label
  res@lbOrientation      = "Vertical" ; vertical label bar
  res@lbLabelFontHeightF = lbLabelFontHeightF 
  res@pmLabelBarWidthF   = 0.1       ; default is shorter
  res@pmLabelBarHeightF  = 0.4        ; default is taller
 ;res@pmLabelBarOrthogonalPosF =  0.03

  res@trYReverse         = False      ; reverse y axis
 ;res@trYMinF            = 0.         ; set minimum Y-axis value
 ;res@trYMaxF            = 8000.      ; set maximum Y-axis value
 ;res@trXMinF            = 1949.      ; set minimum X-axis value
 ;res@trXMaxF            = 2006.      ; set maximum X-axis value

  res@vpHeightF          = 0.4
  res@vpWidthF           = 1.0        ; width of contour plots

;;----------------------------------------------------------------------
;; axis  
;;----------------------------------------------------------------------
  res@tiXAxisFontHeightF = tiXAxisFontHeightF
  res@tiYAxisFontHeightF = tiYAxisFontHeightF 

;;----------------------------------------------------------------------
;; tickmark 
;;----------------------------------------------------------------------
  res@tmYLMode = "Explicit"	
  res@tmYLValues = (/100.,200.,400.,600.,800.,1000.,2000.,3000.,4000./)
  res@tmYLLabels = (/"100","200","400","600","800","1000","2000","3000","4000"/)
  res@tmYLMinorValues  = ispan(0,4000,200)

  res@tmXBLabelFontHeightF = tmXBLabelFontHeightF
  res@tmYLLabelFontHeightF = tmYLLabelFontHeightF

  res@gsnRightString = strx
 
;;----------------------------------------------------------------------
;; plot array 
;;----------------------------------------------------------------------

  plot = new(9,graphic)                          ; create graphical array

;;----------------------------------------------------------------------
;; ANN panel 1 
;;----------------------------------------------------------------------

  ip = 0 

  res@gsnLeftString   = abcd(ip) + " ANN"
 ;res@gsnLeftString   = gsnLeftString(ip) 
 ;res@gsnCenterString = gsnCenterString(ip) 
  res@cnLinesOn       = lavgLinesOn 
  res@cnLineLabelsOn  = False
  res@cnFillOn        = True     ; turn on color
  res@cnMinLevelValF  = 1.       ; set min contour level
  res@cnMaxLevelValF  = 9.       ; set max contour level
  res@cnLevelSpacingF = 1.
  res@lbLabelStride   = 1          ; every other label bar label
  res@lbLabelBarOn    = True       ; no individual label bar
  res@tiYAxisString   = tiYAxisString(ip) 
  plot(ip) = gsn_csm_contour(wks,prna,res)
 
;;----------------------------------------------------------------------
;; line over color 
;;----------------------------------------------------------------------

  if (lpercentilesOn) then
  res@cnFillOn        = False
  res@cnLinesOn       = True 
  res@cnLineThicknessF= 2.
  res@cnLineLabelsOn  = True 
  res@cnLineLabelFontHeightF = cnLineLabelFontHeightF 
 ;res@cnMonoLineDashPattern  = True
  res@cnLineLabelPlacementMode = "Constant" 
  res@cnLineDashPatterns  = 2   ; Define line patterns.
  res@cnLineDashSegLenF   = 0.18          ; assist in controlling concentration
  res@cnLineLabelInterval = 1             ; default = 2 
  res@cnMinLevelValF  = 4.      ; set min contour level
  res@cnMaxLevelValF  = 12.   ; set max contour level
  res@cnLevelSpacingF = 4. 
  res@lbLabelStride   = 1       ; every other label bar label
  plot(ip) = gsn_csm_contour(wks,prma,res)
  overlay(plot(ip),plotover)                              ; now over lay plots 
  delete(plotover) 
  end if

  print("") 
  print("done pannel: "+ip)  

;;----------------------------------------------------------------------
;; ANN panel 2 
;;----------------------------------------------------------------------

  ip = ip + 1  

  res@gsnLeftString = abcd(ip) + " ANN"
 ;res@gsnLeftString   = gsnLeftString(ip) 
 ;res@gsnCenterString = gsnCenterString(ip) 
  res@cnLinesOn       = lavgLinesOn 
  res@cnLineLabelsOn  = False
  res@cnFillOn        = True     ; turn on color
  res@cnMinLevelValF  = 1.    ; set min contour level
  res@cnMaxLevelValF  = 9.    ; set max contour level
  res@cnLevelSpacingF = 1.
  res@lbLabelStride   = 1        ; every other label bar label
  res@lbLabelBarOn       = True       ; no individual label bar
 ;res@tiYAxisString    = "" 
  plot(ip) = gsn_csm_contour(wks,prnf,res)
 
;;----------------------------------------------------------------------
;; line over color 
;;----------------------------------------------------------------------

  if (lpercentilesOn) then
  res@cnFillOn        = False   ; turn on color
  res@cnLinesOn       = True    ; turn off contour lines
  res@cnLineLabelsOn  = True 
  res@cnLineThicknessF= 2.      ; thicker lines
  res@cnLineLabelFontHeightF = cnLineLabelFontHeightF 
 ;res@cnMonoLineDashPattern  = True
  res@cnLineLabelPlacementMode = "Constant" 
  res@cnLineDashPatterns  = 2   ; Define line patterns.
  res@cnLineDashSegLenF   = 0.18          ; assist in controlling concentration
  res@cnLineLabelInterval = 1             ; default = 2 
  res@cnMinLevelValF  = 4.      ; set min contour level
  res@cnMaxLevelValF  = 12.   ; set max contour level
  res@cnLevelSpacingF = 4. 
  res@lbLabelStride   = 1       ; every other label bar label
  plotover = gsn_csm_contour(wks,prmf,res)          ; draw second plot
  overlay(plot(ip),plotover)                              ; now over lay plots 
  delete(plotover) 
  end if

  print("done pannel: "+ip)  

;;----------------------------------------------------------------------
;; ANN panel 3 
;;----------------------------------------------------------------------

  ip = ip + 1  

  res@gsnLeftString = abcd(ip) + " ANN"
 ;res@gsnLeftString   = gsnLeftString(ip) 
 ;res@gsnCenterString = gsnCenterString(ip) 
  res@cnLinesOn       = lavgLinesOn 
  res@cnLineLabelsOn  = False
  res@cnFillOn        = True     ; turn on color
  res@cnMinLevelValF  = 1.       ; set min contour level
  res@cnMaxLevelValF  = 9.       ; set max contour level
  res@cnLevelSpacingF = 1.
  res@lbLabelStride   = 1          ; every other label bar label
  res@lbLabelBarOn    = True       ; no individual label bar
 ;res@tiYAxisString   = "" 
  plot(ip) = gsn_csm_contour(wks,prni,res)

;;----------------------------------------------------------------------
;; line over color 
;;----------------------------------------------------------------------

  if (lpercentilesOn) then
  res@cnFillOn         = False   ; turn on color
  res@cnLinesOn        = True    ; turn off contour lines
  res@cnLineLabelsOn  = True 
  res@cnLineThicknessF = 2.      ; thicker lines
  res@cnLineLabelFontHeightF = cnLineLabelFontHeightF 
 ;res@cnMonoLineDashPattern  = True
  res@cnLineLabelPlacementMode = "Constant" 
  res@cnLineDashPatterns  = 2   ; Define line patterns.
  res@cnLineDashSegLenF   = 0.18          ; assist in controlling concentration
  res@cnLineLabelInterval = 1             ; default = 2 
  res@cnMinLevelValF  = 4.      ; set min contour level
  res@cnMaxLevelValF  = 12.   ; set max contour level
  res@cnLevelSpacingF = 4. 
  res@lbLabelStride       = 1              ; every other label bar label
  plotover = gsn_csm_contour(wks,prmi,res) ; draw second plot
  overlay(plot(ip),plotover)               ; now over lay plots 
  delete(plotover) 
  end if

  print("done pannel: "+ip)  

;;----------------------------------------------------------------------
;; DJF panel 1 
;;----------------------------------------------------------------------

  ip = ip + 1  

  res@gsnLeftString = abcd(ip) + " DJF"
 ;res@gsnLeftString   = gsnLeftString(ip) 
 ;res@gsnCenterString = gsnCenterString(ip) 
 ;res@tiYAxisString   = tiYAxisString(ip) 
  res@cnLinesOn       = lavgLinesOn 
  res@cnLineLabelsOn  = False
  res@cnFillOn        = True     ; turn on color
  res@cnMinLevelValF  = 1.       ; set min contour level
  res@cnMaxLevelValF  = 9.       ; set max contour level
  res@cnLevelSpacingF = 1.
  res@lbLabelStride   = 1        ; every other label bar label
 ;res@tmYLLabelsOn    = False    ; no y left tm labels
 ;res@tiYAxisOn       = False    ; no y-axis title
  res@lbLabelBarOn    = True       ; no individual label bar
  plot(ip) = gsn_csm_contour(wks,prnb,res)

;;----------------------------------------------------------------------
;; line over color 
;;----------------------------------------------------------------------

  if (lpercentilesOn) then
  res@cnFillOn        = False   ; turn on color
  res@cnLinesOn       = True    ; turn off contour lines
  res@cnLineLabelsOn  = True 
  res@cnLineThicknessF= 2.      ; thicker lines 
  res@cnMinLevelValF  = 4.      ; set min contour level
  res@cnMaxLevelValF  = 12.   ; set max contour level
  res@cnLevelSpacingF = 4. 
  res@lbLabelStride   = 1       ; every other label bar label
  plotover = gsn_csm_contour(wks,prmb,res)          ; draw second plot
  overlay(plot(ip),plotover)                              ; now over lay plots
  delete(plotover)
  end if

  print("done pannel: "+ip)  

;;----------------------------------------------------------------------
;; DJF panel 2
;;----------------------------------------------------------------------

  ip = ip + 1  

  res@gsnLeftString = abcd(ip) + " DJF"
 ;res@gsnLeftString   = gsnLeftString(ip) 
 ;res@gsnCenterString = gsnCenterString(ip) 
 ;res@tiYAxisString    = "" 
  res@cnLinesOn       = lavgLinesOn 
  res@cnLineLabelsOn  = False
  res@cnFillOn        = True     ; turn on color
  res@cnMinLevelValF  = 1.    ; set min contour level
  res@cnMaxLevelValF  = 9.       ; set max contour level
  res@cnLevelSpacingF = 1.
  res@lbLabelStride   = 1        ; every other label bar label
 ;res@tmYLLabelsOn    = False    ; no y left tm labels
 ;res@tiYAxisOn       = False    ; no y-axis title
  res@lbLabelBarOn    = True     ; no individual label bar
  plot(ip) = gsn_csm_contour(wks,prng,res)

;;----------------------------------------------------------------------
;; line over color 
;;----------------------------------------------------------------------

  if (lpercentilesOn) then
  res@cnFillOn        = False   ; turn on color
  res@cnLinesOn       = True    ; turn off contour lines
  res@cnLineLabelsOn  = True 
  res@cnLineThicknessF= 2.      ; thicker lines 
  res@cnMinLevelValF  = 4.      ; set min contour level
  res@cnMaxLevelValF  = 12.   ; set max contour level
  res@cnLevelSpacingF = 4. 
  res@lbLabelStride   = 1       ; every other label bar label
  plotover = gsn_csm_contour(wks,prmg,res)          ; draw second plot
  overlay(plot(ip),plotover)                        ; now over lay plots
  delete(plotover)
  end if

  print("done pannel: "+ip)  

;;----------------------------------------------------------------------
;; DJF panel 3
;;----------------------------------------------------------------------

  ip = ip + 1  

  res@gsnLeftString  = abcd(ip) + " DJF"
 ;res@gsnLeftString   = gsnLeftString(ip) 
 ;res@gsnCenterString = gsnCenterString(ip) 
 ;res@tiYAxisString   = "" 
  res@cnLinesOn       = lavgLinesOn 
  res@cnLineLabelsOn  = False
  res@cnFillOn        = True     ; turn on color
  res@cnMinLevelValF  = 1.       ; set min contour level
  res@cnMaxLevelValF  = 9.       ; set max contour level
  res@cnLevelSpacingF = 1.
  res@lbLabelStride   = 1         ; every other label bar label
 ;res@tmYLLabelsOn    = False     ; no y left tm labels
 ;res@tiYAxisOn       = False     ; no y-axis title
  res@lbLabelBarOn    = True      ; no individual label bar
  plot(ip) = gsn_csm_contour(wks,prnj,res)

;;----------------------------------------------------------------------
;; line over color 
;;----------------------------------------------------------------------

  if (lpercentilesOn) then
  res@cnFillOn        = False   ; turn on color
  res@cnLinesOn       = True    ; turn off contour lines
  res@cnLineLabelsOn  = True 
  res@cnLineThicknessF= 2.      ; thicker lines 
  res@cnMinLevelValF  = 4.      ; set min contour level
  res@cnMaxLevelValF  = 12.   ; set max contour level
  res@cnLevelSpacingF = 4. 
  res@lbLabelStride   = 1       ; every other label bar label
  plotover = gsn_csm_contour(wks,prmj,res)          ; draw second plot
  overlay(plot(ip),plotover)                        ; now over lay plots
  delete(plotover)
  end if

  print("done pannel: "+ip)  

;;----------------------------------------------------------------------
;; JJA panel 1 
;;----------------------------------------------------------------------

  ip = ip + 1  

  res@gsnLeftString  = abcd(ip) + " JJA"
 ;res@gsnLeftString   = gsnLeftString(ip) 
 ;res@gsnCenterString = gsnCenterString(ip) 
  res@tiYAxisString   = tiYAxisString(ip) 
  res@cnLinesOn       = lavgLinesOn 
  res@cnLineLabelsOn  = False
  res@cnFillOn        = True     ; turn on color
  res@cnMinLevelValF  = 1.       ; set min contour level
  res@cnMaxLevelValF  = 9.       ; set max contour level
  res@cnLevelSpacingF = 1.
  res@lbLabelStride   = 1         ; every other label bar label
 ;res@tmYLLabelsOn    = False     ; no y left tm labels
 ;res@tiYAxisOn       = False     ; no y-axis title
  res@lbLabelBarOn    = True      ; no individual label bar
  plot(ip) = gsn_csm_contour(wks,prnc,res)

;;----------------------------------------------------------------------
;; line over color 
;;----------------------------------------------------------------------

  if (lpercentilesOn) then
  res@cnFillOn        = False   ; turn on color
  res@cnLinesOn       = True    ; turn off contour lines
  res@cnLineLabelsOn  = True 
  res@cnLineThicknessF= 2.      ; thicker lines
  res@cnMinLevelValF  = 2000.   ; set min contour level
  res@cnMaxLevelValF  = 8000.   ; set max contour level
  res@cnLevelSpacingF = 2000.   ; 
  res@cnMinLevelValF  = 4.      ; set min contour level
  res@cnMaxLevelValF  = 12.   ; set max contour level
  res@cnLevelSpacingF = 4. 
  res@lbLabelStride   = 1       ; every other label bar label
  plotover = gsn_csm_contour(wks,prmc,res)          ; draw second plot
  overlay(plot(ip),plotover)                        ; now over lay plots
  end if

  print("done pannel: "+ip)  

;;----------------------------------------------------------------------
;; JJA panel 2 
;;----------------------------------------------------------------------

  ip = ip + 1  

  res@gsnLeftString  = abcd(ip) + " JJA"
 ;res@gsnLeftString   = gsnLeftString(ip) 
 ;res@gsnCenterString = gsnCenterString(ip) 
 ;res@tiYAxisString   = "" 
  res@cnLinesOn       = lavgLinesOn 
  res@cnLineLabelsOn  = False
  res@cnFillOn        = True     ; turn on color
  res@cnMinLevelValF  = 1.       ; set min contour level
  res@cnMaxLevelValF  = 9.       ; set max contour level
  res@cnLevelSpacingF = 1.
  res@lbLabelStride   = 1         ; every other label bar label
 ;res@tmYLLabelsOn    = False     ; no y left tm labels
 ;res@tiYAxisOn       = False     ; no y-axis title
  res@lbLabelBarOn    = True      ; no individual label bar
  plot(ip) = gsn_csm_contour(wks,prnh,res)

;;----------------------------------------------------------------------
;; line over color 
;;----------------------------------------------------------------------

  if (lpercentilesOn) then
  res@cnFillOn        = False   ; turn on color
  res@cnLinesOn       = True    ; turn off contour lines
  res@cnLineLabelsOn  = True 
  res@cnLineThicknessF= 2.      ; thicker lines
  res@cnMinLevelValF  = 2000.   ; set min contour level
  res@cnMaxLevelValF  = 8000.   ; set max contour level
  res@cnLevelSpacingF = 2000.   ; 
  res@cnMinLevelValF  = 4.      ; set min contour level
  res@cnMaxLevelValF  = 12.   ; set max contour level
  res@cnLevelSpacingF = 4. 
  res@lbLabelStride   = 1       ; every other label bar label
  plotover = gsn_csm_contour(wks,prmh,res)          ; draw second plot
  overlay(plot(ip),plotover)                        ; now over lay plots
  end if

  print("done pannel: "+ip)  

;;----------------------------------------------------------------------
;; JJA panel 3
;;----------------------------------------------------------------------

  ip = ip + 1  

  res@gsnLeftString  = abcd(ip) + " JJA"
 ;res@gsnLeftString   = gsnLeftString(ip) 
 ;res@gsnCenterString = gsnCenterString(ip) 
 ;res@tiYAxisString   = "" 
  res@cnLinesOn       = lavgLinesOn 
  res@cnLineLabelsOn  = False
  res@cnFillOn        = True     ; turn on color
  res@cnMinLevelValF  = 1.       ; set min contour level
  res@cnMaxLevelValF  = 9.       ; set max contour level
  res@cnLevelSpacingF = 1.
  res@lbLabelStride   = 1         ; every other label bar label
 ;res@tmYLLabelsOn    = False     ; no y left tm labels
 ;res@tiYAxisOn       = False     ; no y-axis title
  res@lbLabelBarOn    = True      ; no individual label bar
  plot(ip) = gsn_csm_contour(wks,prnk,res)

;;----------------------------------------------------------------------
;; line over color 
;;----------------------------------------------------------------------

  if (lpercentilesOn) then
  res@cnFillOn        = False   ; turn on color
  res@cnLinesOn       = True    ; turn off contour lines
  res@cnLineLabelsOn  = True 
  res@cnLineThicknessF= 2.      ; thicker lines
  res@cnMinLevelValF  = 2000.   ; set min contour level
  res@cnMaxLevelValF  = 8000.   ; set max contour level
  res@cnLevelSpacingF = 2000.   ; 
  res@cnMinLevelValF  = 4.      ; set min contour level
  res@cnMaxLevelValF  = 12.   ; set max contour level
  res@cnLevelSpacingF = 4. 
  res@lbLabelStride   = 1       ; every other label bar label
  plotover = gsn_csm_contour(wks,prmk,res)          ; draw second plot
  overlay(plot(ip),plotover)                        ; now over lay plots
  end if

  print("done pannel: "+ip)  

;;----------------------------------------------------------------------
;; panel plot 
;;----------------------------------------------------------------------

  resp                    = True   ; panel mods desired
  resp@gsnFrame           = False  ; don't advance frame yet
 ;resp@gsnPanelBottom     = 0.0    ; space for label bar
 ;resp@gsnPanelTop        = 0.5    ; only panel on lower half of page
 ;resp@gsnPanelLabelBar   = True   ; common label bar
 ;resp@pmLabelBarWidthF   = 0.8    ; label bar width
 
  resp@gsnPanelYWhiteSpacePercent = 8
  resp@gsnPanelXWhiteSpacePercent = 0
 
 ;gsn_panel(wks,plot(0:8),(/3,3/),resp)
  gsn_panel(wks,(/plot(2),plot(5),plot(8)/),(/3,1/),resp)

  frame(wks) 

  system("ps2pdf "+ploteps+" "+plotpdf)
  system("mpack -s "+ploteps+" -a "+plotpdf+" k.zhang.iap@gmail.com")


  ;; output plot information 


end
 
          


